<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/*防沉迷相关控制器*/
class Identity extends MY_Controller {
	public function __construct()
	{
		parent::__construct();
		$this->__validation();
        $this->load->model('Identity_model','Identity');
	}
	public function isvalid()
	{
		$uid = intval($this->params['uid']);
		$result = $this->Identity->getIdentity($uid);
		$this->response['code'] = 0;
		$this->response['data'] = $result ? TRUE : FALSE;
		$this->_print();
	}

	public function update()
	{
		$uid = intval($this->params['uid']);
		$identity = $this->params['identity'];
		$this->load->helper('utility');
		if(!checkID($identity))
		{
			$this->setResponse('IDENTITY_NOT_VALIDAT');
		}
		else 
		{
			$rtn = $this->Identity->updateIdentity($uid,$identity,$this->params['realname']);
			$this->setResponse($rtn ? 'OK' :'UPDATE_IDENTITY_ERROR');
		}
		$this->_print();
	}

	public function query()
	{
		$uid = intval($this->params['uid']);
		$rtn = $this->Identity->getIdentity($uid);
		if($rtn)
		{
			$this->setResponse('OK',array('identity'=>$rtn->identitycode,'realname'=>$rtn->realname));
		}
		else
			$this->setResponse('IDENTITY_NOT_FOUND');
		$this->_print();
	}

}